package com.dragon.app.concurrent;

import static java.util.concurrent.Executors.newSingleThreadExecutor;

import java.lang.ref.PhantomReference;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.concurrent.*;
import java.util.concurrent.atomic.AtomicReference;
import java.util.concurrent.atomic.AtomicStampedReference;
import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReadWriteLock;
import java.util.concurrent.locks.ReentrantLock;
import java.util.concurrent.locks.ReentrantReadWriteLock;

public class Test {

	public static void main(String[] args) throws InterruptedException {
		
		AtomicReference atomicReference;
		AtomicStampedReference atomicStampedReference;
		PhantomReference phantomReference;


		ArrayList arrayList;
		CopyOnWriteArrayList copyOnWriteArrayList;
		CopyOnWriteArraySet copyOnWriteArraySet;
		ConcurrentHashMap concurrentHashMap;
		
		Lock lock = new ReentrantLock();
		ReadWriteLock readWriteLock = new ReentrantReadWriteLock();
		readWriteLock.writeLock().lock();
		readWriteLock.writeLock().unlock();
		
		CountDownLatch countDownLatch;
		CyclicBarrier cyclicBarrier;
		Semaphore semaphore;
		
		SynchronousQueue blockingQueue = new SynchronousQueue<>();
		new Thread(()->{
			System.out.println("消费者来了。。");
			try {
				blockingQueue.take();
			} catch (InterruptedException e) {
				e.printStackTrace();
			}
			System.out.println("消费者拿到了。。");
		}).start();
		Thread.sleep(1000);
		blockingQueue.put("add");


		
		
		//不推荐使用Executors创建线程池，有风险
		ExecutorService newFixedThreadPool = Executors.newFixedThreadPool(1);
		ExecutorService newSingleThreadExecutor = newSingleThreadExecutor();
		ExecutorService newCachedThreadPool = Executors.newCachedThreadPool();
		ExecutorService newScheduledThreadPool = Executors.newScheduledThreadPool(1);
		
		System.out.println(Integer.MAX_VALUE);
		
		/*System.out.println(System.getProperties());*/
		
		System.out.println(Runtime.getRuntime().availableProcessors());


		BlockingQueue blockingQueue1 = new LinkedBlockingQueue();
		ConcurrentLinkedQueue concurrentLinkedQueue;
		HashMap hashMap;

		FutureTask futureTask;

		String lock1 = "lock1";
		String lock2 = "lock2";
		synchronized (lock1){
			lock1.notify();
		}
		// 必须获取该对象的monitor才能调用wait或者notify
		/*synchronized (lock2){
			lock1.notify();
		}*/

		

	}

}
